<template>
  <div>
    <h3>登录页面</h3>
    <div> 账号：<input type="text" v-model="user.username"> </div>
     <div> 密码：<input type="text" v-model="user.password"> </div>
     <div> <button @click="log">登录</button>  </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
     data(){
        return{
            user:{
                username:'',
                password:'',
            }
        }
    },
    methods:{
        log(){
            axios.post('login/',this.user)
            .then(resp=>{
                console.log(resp);
                if(resp.data.code == 200){
                    alert('登录成功')
                    this.$store.commit('setUser',resp.data.user)
                    this.$router.push('/index')
                }else{
                    alert(resp.data.msg)
                }
            })
            .catch(err=>{
                console.log(err);
            })
        }
    }
}
</script>

<style>

</style>